using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Qibla.Library;

namespace Qibla
{
    public partial class EnterCoordinatesFrm : Form
    {
        public EnterCoordinatesFrm()
        {
            InitializeComponent();
        }

        private PointD _startCoordinate;

        public PointD StartCoordinate
        {
            get { return _startCoordinate; }
            set { _startCoordinate = value; }
        }

        private PointD _endCoordinate;

        public PointD EndCoordinate
        {
            get { return _endCoordinate; }
            set { _endCoordinate = value; }
        }



        private void btnOk_Click(object sender, EventArgs e)
        {
            if ((tbStartLat.Text == string.Empty) && 
                (tbStartLong.Text == string.Empty) && 
                (tbEndLat.Text == string.Empty) &&
                (tbEndLong.Text == string.Empty))
            {
                DialogResult = DialogResult.Cancel;
                Close();
            }
            else
            {
                double endLat = 0;
                double endLong = 0;
                double stLat = 0;
                double stLong = 0;

                try
                {
                    stLat = Convert.ToDouble(tbStartLat.Text);
                }
                catch
                {
                    lblErrors.Text = Strings.Error_InvalidStartLat;
                    return;
                }

                try
                {
                    stLong = Convert.ToDouble(tbStartLong.Text);
                }
                catch
                {
                    lblErrors.Text = Strings.Error_InvalidStartLong;
                    return;
                }

                try
                {
                    endLat = Convert.ToDouble(tbEndLat.Text);
                }
                catch
                {
                    lblErrors.Text = Strings.Error_InvalidEndLat;
                    return;
                }

                try
                {
                    endLong = Convert.ToDouble(tbEndLong.Text);
                }
                catch
                {
                    lblErrors.Text = Strings.Errror_InvalidEndLong;
                    return;
                }

                _startCoordinate = new PointD(stLong, stLat);
                _endCoordinate = new PointD(endLong, endLat);
                DialogResult = DialogResult.OK;

                Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult =  DialogResult.Cancel;
        }
    }
}